package com.alit.monitor.service;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.springframework.stereotype.Service;

/**
 * @author litong
 * @date 2019年4月15日_下午6:52:24
 * @version 1.0
 */
@Service
public class DetectionUrlService {
	/**
	 * 检测测url地址,返回状态码
	 * 
	 * @param url
	 * @return
	 */
	public int detectionURL(String url) {
		HttpClient httpClient = new HttpClient();
		int retval = 0;
		GetMethod getMethod = new GetMethod(url);
		try {
			retval = httpClient.executeMethod(getMethod);
		} catch (HttpException e) {
			e.printStackTrace();
			getMethod.releaseConnection();
		} catch (IOException e) {
			e.printStackTrace();
			getMethod.releaseConnection();
		}
		getMethod.releaseConnection();
		return retval;
	}
}
